<?php
class ControllerAffiliateTransaction extends FrontController {
	public function index() {
		if (!$this->affiliate->isLogged()) {
			$this->session->data['redirect'] = US('affiliate/transaction');
	  		$this->redirect(US('affiliate/login'));
    	}

		$this->document->setTitle($this->_['heading_title']);

      	$this->data['breadcrumbs'][] = array(
        	'text'      => $this->_['text_account'],
			'href'      => US('affiliate/account'),
        	'separator' => $this->_['text_separator']
      	);

      	$this->data['breadcrumbs'][] = array(
        	'text'      => $this->_['text_transaction'],
			'href'      => US('affiliate/transaction'),
        	'separator' => $this->_['text_separator']
      	);

		M('affiliate/transaction');

		$page = G('page', 1);
		
		$this->data['transactions'] = array();

		$transaction_total = $this->model_affiliate_transaction->getTotalTransactions();
		$results = $this->model_affiliate_transaction->getTransactions(($page - 1) * 10);

    	foreach ($results as $result) {
			$this->data['transactions'][] = array(
				'amount'      => $this->currency->format($result['amount'], C('config_currency')),
				'description' => $result['description'],
				'date_added'  => v5_date_format($result['date_added'])
			);
		}

		$this->data['pagination'] = $this->pagination($transaction_total, $page, null, 10)->render();

		$this->data['balance'] = $this->currency->format($this->model_affiliate_transaction->getBalance());

		$this->display('affiliate/transaction.tpl');
	}
}
?>